# coding:utf-8
from selenium.webdriver.support.ui import WebDriverWait                # 导入显示等待方法
from selenium.webdriver.support import expected_conditions as EC       # 导入判断元素是否存在方法
import os                                                              # 导入操作系统方法

PATH = lambda x: os.path.join(os.path.dirname(os.path.realpath(__file__)), x)


def always_allow(self):
    '''
    fuction:权限弹窗--始终允许
    args:1.传driver
    2.number，判断弹窗次数，默认给3次
    其它：WebDriverWait里面0.5s判断一次是否有弹窗，1s超时
    '''
    for i in range(3):
        loc = ("xpath", "//*[@text='仅在使用中允许']")
        try:
            e = WebDriverWait(self, 1, 0.5).until(EC.presence_of_element_located(loc))
            e.click()
        except:
            pass


    for i in range(3):
        loc = ("xpath", "//*[@text='始终允许']")
        try:
            e = WebDriverWait(self, 1, 0.5).until(EC.presence_of_element_located(loc))
            e.click()
        except:
            pass


    for i in range(3):
        loc = ("xpath", "//*[@text='仅在使用中允许']")
        try:
            e = WebDriverWait(self, 1, 0.5).until(EC.presence_of_element_located(loc))
            e.click()
        except:
            pass






